package io.renren.modules.generator.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author rose
 * @create 2021/8/7
 */

/**
 * 这个类的静态方法用来根据当前时间生成FTP服务器上面的目录
 */
public class FTPUtil {

    final static int [] sizeTable = { 9, 99, 999, 9999, 99999, 999999, 9999999,
            99999999, 999999999, Integer.MAX_VALUE };

    // Requires positive x

    /**
     * 判断当前位数；
     * @param x
     * @return
     */
    static int stringSize(int x) {
        for (int i=0; ; i++)
            if (x <= sizeTable[i])
                return i+1;
    }
    public static String genePath(){
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("MMddHH");
        String string = formatter.format(date);
        String mm = string.substring(0,2);
        String dd =string.substring(2,4);
        String hh = string.substring(4);
        if(new Integer(hh) - 9>0){
//            System.out.println(dd+ (new Integer(hh) - 9));
            if (stringSize((new Integer(hh) - 9)) == 1){
                // 对不够两位的hh补0
                return mm + "/" + dd + "/0" + (new Integer(hh) - 9)+"/";
            }else{
                return mm + "/" + dd + "/" + (new Integer(hh) - 9)+"/";
            }

        }else {
//            System.out.println(new Integer(dd) -1);
//            System.out.println(new Integer(hh) - 9 +24);
            if (stringSize((new Integer(dd) - 1)) == 1){
                //对天数这种补0
                // todo  目前没有做的是如果是1号补减1就变成了0 ，然后就需要月份往上减
                return mm +"/0"+(new Integer(dd) -1)+"/" +(new Integer(hh) - 9 +24)+"/";
            }else{
                return mm +"/"+(new Integer(dd) -1)+"/" +(new Integer(hh) - 9 +24)+"/";
            }


        }

    }
}
